# Maintainer: Antonio Rojas <arojas@archlinux.com>

_pyname=jupyter_server_ydoc
pkgname=jupyter-server-ydoc
pkgver=0.8.0
pkgrel=5
pkgdesc='A Jupyter Server Extension Providing Y Documents'
arch=(any)
url='https://jupyter.org/'
license=(BSD)
depends=(jupyter-server python-jupyter-ydoc jupyter-server-fileid)
makedepends=(python-build python-installer python-hatchling)
checkdepends=(python-pytest-timeout python-pytest-jupyter)
source=(https://pypi.python.org/packages/source/j/$_pyname/$_pyname-$pkgver.tar.gz
        https://github.com/jupyterlab/jupyter_collaboration/commit/6e684048.patch)
sha256sums=('a6fe125091792d16c962cc3720c950c2b87fcc8c3ecf0c54c84e9a20b814526c'
            '72c8386df9a167b1d29c61e4e66969a8731aff9094c63c90877202d5c9fc2f71')

prepare() {
  patch -d $_pyname-$pkgver -p1 < 6e684048.patch # Fix on_document_change signature
  sed -e 's|jupyter_ydoc>=0.2.0,<0.4.0|jupyter_ydoc|' -e 's|ypy-websocket>=0.8.2,<0.9.0|ypy-websocket|' -i $_pyname-$pkgver/pyproject.toml
}

build() {
  cd $_pyname-$pkgver
  python -m build --wheel --no-isolation
}

check() {
  cd $_pyname-$pkgver
  pytest -v
}

package() {
  cd $_pyname-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -Dm644 LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname
  mv "$pkgdir"/{usr/,}etc
}
